import { Application } from 'egg';
import {
  indexRule,
  createRule,
  updateRule,
  destroyRule,
 } from '../validate/shop/nav';

/**
 * 导航管理
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const {  jwt } = app;

  return {
    'merchant.nav.list': {
      method: 'GET',
      path: '/api/merchant/nav',
      options: {
        tags: ['type/list'],
        description: '导航列表',
        handler: app.controller.shop.nav.list,
        middlewares: [jwt, auth('merchant.nav.list')],
        validate: indexRule,
      },
    },
    'merchant.nav.create': {
      method: 'POST',
      path: '/api/merchant/nav',
      options: {
        tags: ['type/create'],
        description: '创建导航',
        handler: app.controller.shop.nav.create,
        middlewares: [jwt, auth('merchant.nav.create')],
        validate: createRule,
      },
    },
    'merchant.nav.update': {
      method: 'PUT',
      path: '/api/merchant/nav/:id',
      options: {
        tags: ['type/update'],
        description: '更新导航',
        handler: app.controller.shop.nav.update,
        middlewares: [jwt, auth('merchant.nav.update')],
        validate: updateRule,
      },
    },
    'merchant.nav.destroy': {
      method: 'DELETE',
      path: '/api/merchant/nav/:id',
      options: {
        tags: ['type/delete'],
        description: '删除导航',
        handler: app.controller.shop.nav.destroy,
        middlewares: [jwt, auth('merchant.nav.destroy')],
        validate: destroyRule,
      },
    }
  };
};
